const {VM, VMScript, NodeVM} = require('vm2');
var catvm2 = require(__dirname + '\\CatVm2\\catvm2.node.js')
var fs = require('fs');

function sdk(e, num) {
    var catvm2code = catvm2.GetCode({
        proxy: true, bug: false
    }, `
    catvm.AddPlugin({description:"npAlisSOLogin Plugin",filename:"lnpalissologin.dll" ,name:"AlissOLogin plugin",MimeTypes:[{description: "AliSSOLogin " ,suffixes: "AlisSOLogin" ,type: "application/npalissologin." },{description: "AlissoLogin1" ,suffixes: "AlissoLogin" ,type: "application1/npalissologin"}]});
    catvm.AddPlugin({description:"Portable Document Format",filename:"internal-pdf-viewer" ,name:"Chrome PDF Viewer",MimeTypes:[{description: "AliSSOLogin " ,suffixes: "AlisSOLogin" ,type: "application/npalissologin." },{description: "AlissoLogin1" ,suffixes: "AlissoLogin" ,type: "application1/npalissologin"}]});
    `, `
    catvm.memory.htmlelements['div']({
        catvm_name:"div",
        id:"cf-content",
        style:{"display":"none"}
    })
    
    catvm.memory.htmlelements['form']({
        catvm_name:"form",
        id:"challenge-form",
        class:"challenge-form",
        action:"/api/v1/members?__cf_chl_f_tk=${e}",
        method:"POST",enctype:"application/x-www-form-urlencoded",
        style:{"display":"none"}
    })
    
    
    catvm.memory.htmlelements['div']({
        catvm_name:"div",
        id:"no-cookie-warning",
        class:"cookie-warning",
        "data-translate":"turn_on_cookies",
        style:{"display":"none"}
    })
    
    document.body = catvm.memory.htmlelements['body']();
    location.href = "https://admindashboard.metalinkerd.com/api/v1/members";
    location.search = '?__cf_chl_rt_tk=${e}';
    location.origin = "https://admindashboard.metalinkerd.com";
    catvm.data.next_status = ${num};
    // catvm.data.xmldata =  ;

    `);
    const codefile = "D:\\dingstock\\dingstock_Project\\yrx\\js_nx\\5s\\cloudfalre_ast\\5s\\5s_1_out.js";
    // const codefile = "D:\\dingstock\\dingstock_Project\\yrx\\zhiyuan_kjia\\5s_1.js";
    //xhr  请求方法模块
    const vm = new VM(
        // {
        //     sandbox: {
        //         qwe :setTimeout
        //     }
        // }
    );

    var data = new VMScript(catvm2code + "(function neqwe(){\n" + fs.readFileSync(codefile) + "\n;" +
        "for (let i = 0; i < catvm.memory.setTimeout.length; i++) {\n" +
        "    if (catvm.memory.setTimeout[i][\"name\"] === undefined && catvm.memory.setTimeout[i][\"arg\"].indexOf(\"/cdn-cgi/challenge-platform\") !==-1){\n" +
        "        sendRequest(catvm.memory.setTimeout[i][\"arg\"])\n" +
        "    }else {\n" +
        "        catvm.memory.setTimeout[i][\"name\"](catvm.memory.setTimeout[i][\"arg\"])\n" +
        "    }\n" +
        "};;return catvm.data})()", `${__dirname}调试代码.js`)
    return JSON.stringify(vm.run(data))
}

// if ()
// for (let i = 0; i < catvm.memory.setTimeout.length; i++) {
//     if (catvm.memory.setTimeout[i]["name"] === undefined && catvm.memory.setTimeout[i]["arg"].indexOf("/cdn-cgi/challenge-platform") !==-1){
//         sendRequest(catvm.memory.setTimeout[i]["arg"])
//     }else {
//         catvm.memory.setTimeout[i]["name"](catvm.memory.setTimeout[i]["arg"])
//     }
// }

// sdk()
console.log(sdk("enP1NLsI6gfMF5C_SJ7HjGUm2_pDN3ZULZ0HkZlW658-1644975538-0-gaNycGzNB5E",  1))
// console.log(sdk("zQ6gztvV4oxmNlALErzfKypbA7Z2vPD8eRwxcs2e5D0-1644475902-0-gaNycGzNB5E"))
// debugger;




